package zl.io;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.io.FileWriter;
import java.io.Reader;
import java.io.FileReader;
import java.io.FileNotFoundException;

public class IODemo03
{
	public static void main(String[] args)
	{
		File file = new File("C:" + File.separator + "Test.txt");
		Writer writer = null;
		Reader reader = null;
		try
		{
			if(file.exists())
			{
				reader = new FileReader(file);
				char[] c = new char[(int)file.length()];
				reader.read(c);
				System.out.println(String.valueOf(c));
			}
			else
			{
				writer = new FileWriter(file);
				String str = "Hello World!!!";
				writer.write(str);
			}
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if(writer != null)
				{
					writer.close();
				}
				else if(reader != null)
				{
					reader.close();
				}
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}
}